package redbook.d20210904.t1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

/**
 * @author habitplus
 * @since 2021-09-04 09:52
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String[] ss = bf.readLine().split(" ");
        int n = Integer.parseInt(ss[0]);
        int k = Integer.parseInt(ss[1]);
        if (n < 1) {
            System.out.println();
            bf.close();
            return;
        }
        ss = bf.readLine().split(" ");
        int[][] arr = new int[n][n];
        for (int i = 0; i < n; i++) {
            Arrays.fill(arr[i], -1);
        }
        Map<Integer, Integer> map = new HashMap<>();
        Map<Integer, List<Integer>> adj = new HashMap<>();
        int a, b, c;
        int cnt = 0; // 结点编号
        for (int i = 0; i < n - 1; i++) {
            a = Integer.parseInt(ss[3 * i]);
            b = Integer.parseInt(ss[3 * i + 1]);
            c = Integer.parseInt(ss[3 * i + 2]);
            if (!map.containsKey(a)) map.put(a, cnt++);
            if (!map.containsKey(b)) map.put(b, cnt++);

            a = map.get(a);
            b = map.get(b);
            arr[a][b] = arr[b][a] = c;
        }
        bf.close();

        // write you code
        int ans = countOfFriends(arr, map, k);
        System.out.println(ans);
    }

    private static int countOfFriends(int[][] edge, Map<Integer, Integer> nodeMap, int k) {
        if (edge == null || edge.length == 0 || edge[0].length == 0) {
            return 0;
        }

        int n = edge.length;
        // 若 visited[i][j] = true，表示已经统计过了
        boolean[][] visited = new boolean[n][n];
        int ans = 0;
        for (Map.Entry<Integer, Integer> e : nodeMap.entrySet()) {
            // 统计从 一点出发，能称为朋友的数量
            ans += count(edge, e.getValue(), visited, k);
        }

        return ans;
    }

    private static int count(int[][] edge, int st, boolean[][] visited, int k) {

        Queue<int[]> que = new LinkedList<>();
        que.offer(new int[]{st, 0});
        int ans = 0;

        while (!que.isEmpty()) {

            for (int i = que.size(); i > 0; i--) {
                int[] node = que.poll();
                int f = node[0];
                // 判断直接相邻的边
                for (int j = 0; j < edge.length; j++) {
                    if (f != j && !visited[f][j] && edge[f][j] != -1) {

                        if (edge[f][j] < k) {
                            // f 和 j 也是朋友
                            visited[f][j] = true;
                            visited[j][f] = true;
                            ans++;
                        }

                        if (edge[f][j] + node[1] < k) {
                            que.offer(new int[]{j, edge[f][j] + node[1]});
                            // 找到 与 st 的一个朋友 j
                            ans++;
                            visited[st][j] = true;
                            visited[j][st] = true;
                        }
                    }
                }
            }
        }
        return ans;
    }
}
